<!doctype html>
<!--
* Tabler - Premium and Open Source dashboard template with responsive and high quality UI.
* @version 1.0.0-beta20
* @link https://tabler.io
* Copyright 2018-2023 The Tabler Authors
* Copyright 2018-2023 codecalm.net Paweł Kuna
* Licensed under MIT (https://github.com/tabler/tabler/blob/master/LICENSE)
-->
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>百家姓加密/解密 - bjx - baijiaxing - Tools</title>
  <link rel="shortcut icon" href="../templates/favicon.svg" />
  <!-- CSS files -->
  <link href="../dist/css/tabler.min.css?1692870487" rel="stylesheet" />
  <link href="../dist/css/tabler-vendors.min.css" rel="stylesheet" />
  <link href="../styles/tabler-iconify-icon.css" rel="stylesheet" />
  <link href="../templates/template.css" rel="stylesheet" />
  <link href="../dist/libs/toastr/toastr.tabler.css" rel="stylesheet" />
  <link href="../styles/pre-code.css" rel="stylesheet" />

  <style>
    @import url('https://cdn.bootcdn.net/ajax/libs/inter-ui/4.0.2/inter.css');

    :root {
      --tblr-font-sans-serif: 'Inter Var', -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
    }

    body {
      font-feature-settings: "cv03", "cv04", "cv11";
    }

    .hide {
      display: none !important;
    }
  </style>
</head>

<body>
  <script src="../dist/js/demo-theme.min.js?1692870487"></script>
  <div class="page">
    <div id="header"></div>
    <!-- Navbar -->

    <div class="page-wrapper">
      <!-- Page header -->
      <div class="page-header d-print-none">
        <div class="container-xl">
          <div class="row g-2 align-items-center">
            <div class="col">
              <h2 class="page-title">百家姓加密/解密</h2>
            </div>
          </div>
        </div>
      </div>
      <!-- Page body -->
      <div class="page-body">
        <div class="container-xl">
          <div class="card">
            <div class="row g-0">
              <div class="col-12 col-md-12 d-flex flex-column">
                <div class="card-body">
                  <div class="mb-3">
                    <label class="form-label">Input text to be encrypted/decrypted</label>
                    <div class="input-group input-group-flat">
                      <textarea class="form-control" rows="5" id="inputText"></textarea>
                      <span class="input-group-text" onclick="$('#inputText').val('')">
                        <i class="icon tabler--x"></i>
                      </span>
                    </div>
                  </div>
                  <div class="mb-3">
                    <a href="javascript:void(0);" class="btn btn-outline-primary" onclick="encode_text()">
                      EnCode
                    </a>
                    <a href="javascript:void(0);" class="btn btn-outline-success" onclick="decode_text()">
                      DeCode
                    </a>
                  </div>
                  <div class="mb-3">
                    <div id="codeblock" class="codeblock codeblock-copyable d-none">
                      <pre class="prismjs language-plaintext">
                                  <code class="language-plaintext" style="white-space:pre" id="outputText">                    
                                  </code>
                              </pre>
                      <div class="codeblock-copy">
                        <button id="codeblock-copy" class="btn btn-icon btn-dark" onclick="copy()">
                          <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clipboard icon"
                            width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"
                            fill="none" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2">
                            </path>
                            <path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z">
                            </path>
                          </svg>
                        </button>
                        <button id="codeblock-copied" class="btn btn-icon btn-green d-none">
                          <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-check" width="24"
                            height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                            stroke-linecap="round" stroke-linejoin="round">
                            <path stroke="none" d="M0 0h24v24H0z" fill="none" />
                            <path d="M5 12l5 5l10 -10" />
                          </svg>
                        </button>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div id="mask" class="mask">
      <div class="mask-content">
        <div id="maskTitle" class="mask-title">正在加载中</div>
        <div class="progress progress-sm">
          <div class="progress-bar progress-bar-indeterminate"></div>
        </div>
      </div>
    </div>

  </div>

  <!-- Libs JS -->
  <script src="../dist/js/tabler.min.js?1692870487" defer></script>
  <script src="../dist/libs/jquery-1.9.1.min.js"></script>
  <script src="../dist/libs/toastr/toastr.tabler.js"></script>
  <script src="../dist/libs/art-template/template-web.min.js"></script>
  <script src="../templates/template.js?v=1.1" defer></script>

  <script>
    var browserInfo;

    $(function () {
      browserInfo = detectDeviceAndOS();
    })

    function encode_text() {
      var inputText = $('#inputText').val().trim();
      if (inputText.length < 1) {
        toastr.error("Please enter text to be encrypted");
        return;
      }
      $('#outputText').html(encode(inputText));
      $("#codeblock").removeClass("d-none");
    }
    function decode_text() {
      var inputText = $('#inputText').val().trim();
      if (inputText.length < 1) {
        toastr.error("Please enter text to be encrypted");
        return;
      }
      $('#outputText').html(decode(inputText));
      $("#codeblock").removeClass("d-none");
    }
    function copy() {
      copyToClipboard($('#outputText').html());
      $("#codeblock-copy").addClass("d-none");
      $("#codeblock-copied").removeClass("d-none");
      setInterval(function () {
        $("#codeblock-copy").removeClass("d-none");
        $("#codeblock-copied").addClass("d-none");
      }, 1000);
    }

    async function copyToClipboardSync(str) {
      try {
        await navigator.clipboard.writeText(str);
        toastr.success('复制成功~');
      } catch (err) {
        toastr.warning(err, '无法复制文本');
      }
    }

    function copyToClipboard(str) {
      if (location.protocol === 'https:') {
        navigator.clipboard.writeText(str).then(() => {
          toastr.success("复制成功~")
        }).catch((err) => {
          toastr.warning(err, "复制失败，请手动复制(╥﹏╥)")
        })
      } else {
        const inputNode = document.createElement('input')
        inputNode.value = str
        document.body.appendChild(inputNode)
        inputNode.select()
        document.execCommand('copy')
        document.body.removeChild(inputNode)
        toastr.success("复制成功~")
      }
    }


    var t = "magnet:?xt=urn:btih:";
    var obja = {
      "赵": "0", "钱": "1", "孙": "2", "李": "3", "周": "4", "吴": "5", "郑": "6", "王": "7", "冯": "8", "陈": "9",
      "褚": "a", "卫": "b", "蒋": "c", "沈": "d", "韩": "e", "杨": "f", "朱": "g", "秦": "h", "尤": "i", "许": "j",
      "何": "k", "吕": "l", "施": "m", "张": "n", "孔": "o", "曹": "p", "严": "q", "华": "r", "金": "s", "魏": "t",
      "陶": "u", "姜": "v", "戚": "w", "谢": "x", "邹": "y", "喻": "z", "福": "A", "水": "B", "窦": "C", "章": "D",
      "云": "E", "苏": "F", "潘": "G", "葛": "H", "奚": "I", "范": "J", "彭": "K", "郎": "L", "鲁": "M", "韦": "N",
      "昌": "O", "马": "P", "苗": "Q", "凤": "R", "花": "S", "方": "T", "俞": "U", "任": "V", "袁": "W", "柳": "X",
      "唐": "Y", "罗": "Z", "薛": ".", "伍": "-", "余": "_", "米": "+", "贝": "=", "姚": "/", "孟": "?", "顾": "#",
      "尹": "%", "江": "&", "钟": "*"
    };;

    function decode(str) {
      str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
      var strc = str.split("");
      var c = "";
      for (var i = 0; i < strc.length; i++) {
        var o = cy(obja, strc[i]);
        c += o;
      }
      c = t + c;
      return c;
    }

    function encode(str) {
      str = str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
      var v = str.replace(/magnet:\?xt=urn:btih:/, "");
      var strc = v.split("");
      var a = "";
      for (var i = 0; i < strc.length; i++) {
        a += ay(obja, strc[i]);
      }
      return a;
    }

    function cy(array, val) {
      for (var key in array) {
        if (key == val) {
          return array[key];
        }
      }
      return '';
    }

    function ay(array, val) {
      for (var key in array) {
        if (array[key] == val) {
          return key;
        }
      }
      return '';
    }

  </script>
</body>

</html>